<!DOCTYPE html>
<html>

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <link rel="Shortcut Icon" href="../images/aecc.ico" type="image/x-icon" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <link href="../StaticFiles/element-plus-2.9.1/index.css" rel="stylesheet">
  <link href="../StaticFiles/nprogress/nprogress.min.css" rel="stylesheet">
  <link href="../styles/vue-page-common.css" rel="stylesheet">
  <script src="../Scripts/pollyfills/Array.prototype.flat.js"></script><!-- es6 数组flat兼容 -->
  <script src="../Scripts/pollyfills/ResizeObserver.js"></script><!-- es6 ResizeObserver兼容  -->
  <script src="../StaticFiles/vue3/vue.global.prod.js"></script>
  <script src="../StaticFiles/element-plus-2.9.1/index.full.min.js"></script>
  <script src="../StaticFiles/element-plus-2.9.1/icons-vue.js"></script><!-- 引入icon -->
  <script src="../StaticFiles/element-plus-2.9.1/zh-cn.min.js"></script><!-- 国际化 -->
  <script src="../Scripts/axios.min.js"></script>
  <script src="../Scripts/axios.config.js"></script>
  <script src="../StaticFiles/nprogress/nprogress.min.js"></script>
  <script src="../Scripts/dayjs.min.js"></script>
  <script src="../Scripts/crypto-js.js"></script>
  <script src="../Scripts/secret.js"></script>
  <title>缺料进度查询报表</title>
  <style>
    .el-table--large .cell {
      padding: 0 10px !important;
    }
  </style>
</head>

<body>
  <div id="app" v-cloak>
    <vue3-report-header title="缺料进度查询报表"></vue3-report-header>
    <div style="padding: 10px;" @keyup.enter="getData">
      <!-- 查询条件区 -->
      <el-form :inline="true" :model="dataObj.queryInfo" ref="queryInfoRef" :label-position="'left'">
        <el-form-item prop='mfgordername' label="订单号:">
          <el-autocomplete v-model.trim="dataObj.queryInfo.mfgordername" placeholder="请输入" :trigger-on-focus="false"
            :fetch-suggestions="getMfgordernameAsync" :value-key="'mfgordername'" :debounce="500" style="width:250px;">
          </el-autocomplete>
        </el-form-item>

        <el-form-item prop='engineno' label="发动机号:">
          <el-autocomplete v-model.trim="dataObj.queryInfo.engineno" placeholder="请输入" :trigger-on-focus="false"
            :fetch-suggestions="getEngineNoAsync" :value-key="'engineno'" :debounce="500" style="width:250px;">
          </el-autocomplete>
        </el-form-item>

        <el-form-item prop='productname' label="零件图号:">
          <el-autocomplete v-model.trim="dataObj.queryInfo.productname" placeholder="请输入" :trigger-on-focus="false"
            :fetch-suggestions="getProductnameAsync" :value-key="'productname'" :debounce="500" style="width:250px;">
          </el-autocomplete>
        </el-form-item>

        <el-form-item label="使用分厂:">
          <el-input v-model.trim="dataObj.queryInfo.uesfactoryname" placeholder="请输入" clearable>
          </el-input>
        </el-form-item>

        <el-form-item label="主制单位:">
          <el-input v-model.trim="dataObj.queryInfo.fevor" placeholder="请输入" clearable>
          </el-input>
        </el-form-item>

        <el-form-item label="计划开始:">
          <el-date-picker v-model="dataObj.queryInfo.startdate" type="daterange" range-separator="至"
            start-placeholder="开始日期" end-placeholder="结束日期" value-format="YYYY-MM-DD" :shortcuts="dataObj.shortcuts">
          </el-date-picker>
        </el-form-item>

        <el-form-item label="计划结束:">
          <el-date-picker v-model="dataObj.queryInfo.enddate" type="daterange" range-separator="至"
            start-placeholder="开始日期" end-placeholder="结束日期" value-format="YYYY-MM-DD" :shortcuts="dataObj.shortcuts">
          </el-date-picker>
        </el-form-item>

        <el-form-item>
          <el-button type="primary" :icon="'Search'" size="default" @click="getData">查询</el-button>
          <el-button type="primary" :icon="'Download'" size="default" @click="getExportExcel">导出</el-button>
        </el-form-item>
      </el-form>

      <!-- 表格 -->
      <el-table :data="dataObj.dataList" stripe border show-overflow-tooltip v-loading.fullscreen.lock="dataObj.loading"
        :element-loading-text="dataObj.loadingText" element-loading-background="rgba(0,0,0,0.8)">
        <el-table-column type="index" width="60"></el-table-column>
        <el-table-column prop="mfgordername" label="订单号" show-overflow-tooltip></el-table-column>
        <el-table-column prop="engineno" label="发动机号" width="140" show-overflow-tooltip></el-table-column>
        <el-table-column prop="ordertype" label="订单类型" width="100" show-overflow-tooltip></el-table-column>
        <el-table-column prop="uesfactoryname" label="使用分厂" width="100" show-overflow-tooltip></el-table-column>
        <el-table-column prop="mfgqty" label="订单数量" width="80" show-overflow-tooltip></el-table-column>
        <el-table-column prop="productfamilyname" label="机型" width="100" show-overflow-tooltip></el-table-column>
        <el-table-column prop="militarytype" label="军种" width="80" show-overflow-tooltip></el-table-column>
        <el-table-column prop="startdate" label="计划开始" width="100" :formatter="splitDate"></el-table-column>
        <el-table-column prop="enddate" label="计划结束" width="100" :formatter="splitDate"></el-table-column>
        <el-table-column prop="seq" label="序号" width="80" show-overflow-tooltip></el-table-column>
        <el-table-column prop="productname" label="组件料号" width="130" show-overflow-tooltip></el-table-column>
        <el-table-column prop="productdesc" label="组件名称" width="140" show-overflow-tooltip></el-table-column>
        <el-table-column prop="factoryname" label="主制单位" width="100" show-overflow-tooltip></el-table-column>
        <el-table-column prop="plannedcompletiondate" label="批次计划完成时间" width="130" :formatter="splitDate">
        </el-table-column>
        <el-table-column prop="qty" label="需求数量" width="80" show-overflow-tooltip></el-table-column>
        <el-table-column prop="lackqty" label="缺料数量" width="80" show-overflow-tooltip>
          <template #default="scope">
            <el-tag :type="scope.row.status" effect="dark">{{scope.row.lackqty}}</el-tag>
          </template>
        </el-table-column>
        <el-table-column label="操作" width="100">
          <template #default="scope">
            <el-link type="primary" @click='getContainer(scope.row)'>查看进度</el-link>
          </template>
        </el-table-column>
      </el-table>

      <!-- 分页 -->
      <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange"
        :current-page="dataObj.currentPage" :page-sizes="[dataObj.pageSize,20,50]" :page-size="dataObj.pageSize"
        layout="prev,pager,next,jumper,sizes,total" :total="dataObj.total">
      </el-pagination>

      <!-- 回到顶部 -->
      <el-backtop></el-backtop>

      <!-- 查看进度弹窗 -->
      <!-- 
        注意：vue2 和 vue3 写法差异
        vue2写法 :visible.sync="dataObj.containerDetail.dialogVisiable"
        vue3写法 v-model="dataObj.containerDetail.dialogVisiable"
      -->
      <el-dialog :width="'98%'" :title="dataObj.containerDetail.title" :top="'15px'"
        v-model="dataObj.containerDetail.dialogVisiable">
        <el-table :data="dataObj.containerDetail.dataList" stripe border ref="table" v-loading="loading"
          v-loading.fullscreen.lock="loading" :element-loading-text="loadingText"
          element-loading-background="rgba(0,0,0,0.8)">
          <el-table-column type="index" width="50" fixed></el-table-column>
          <el-table-column label="零件号" prop="productname" width="140" show-overflow-tooltip></el-table-column>
          <el-table-column label="零件名称" prop="productdescription" width="140" show-overflow-tooltip></el-table-column>
          <el-table-column label="主制单位" prop="factoryname" width="140" show-overflow-tooltip></el-table-column>
          <el-table-column label="订单号" prop="mfgordername" width="140" show-overflow-tooltip></el-table-column>
          <el-table-column label="批次号" prop="containername" width="200" show-overflow-tooltip></el-table-column>
          <el-table-column label="批次数量" prop="qty" width="80" show-overflow-tooltip></el-table-column>
          <el-table-column label="计划开始时间" prop="plannedstartdate" width="120" :formatter="splitDate"></el-table-column>
          <el-table-column label="计划完成时间" prop="plannedcompletiondate" width="120" :formatter="splitDate">
          </el-table-column>
        </el-table>
      </el-dialog>

    </div>
  </div>
  <script type="module">
    import { getProductFamily, exportExcel, getFactory, getParams, fetchSuggestion } from '../Scripts/hooks/useCommonMethod.js'
    import { prevWeek, thisWeek, nextWeek, prevMonth, thisMonth, nextMonth } from '../Scripts/hooks/vue3DateShortCut.js'
    import { splitDate } from '../Scripts/hooks/format.js'
    import Vue3ReportHeader from '../Scripts/components/Vue3ReportHeader.js';
    const { createApp, reactive, ref, onMounted, watch } = Vue
    const { ElMessage } = ElementPlus
    const App = {
      setup() {
        const dataObj = reactive({
          loading: false,
          loadingText: '数据加载中...',
          currentPage: 1,// 当前页
          pageSize: 12, // 每页显示条数
          total: 0,
          queryInfo: {
            mfgordername: '',
            engineno: '',
            productname: '',
            startdate: '',
            enddate: '',
            fevor: '',//主制分厂
            uesfactoryname: ''//使用单位
          },
          dataList: [],
          // 查看进度弹窗
          containerDetail: { dialogVisiable: false, title: '', dataList: [], total: [] },
          shortcuts: [prevWeek, thisWeek, nextWeek, prevMonth, thisMonth, nextMonth]
        })

        // 查询图号
        async function getProductnameAsync(value, callback) {
          fetchSuggestion({ actionName: 'getProductnameAsync', name: 'productname', value, callback, triggerLength: 2 });
        }

        // 查询订单号
        async function getMfgordernameAsync(value, callback) {
          fetchSuggestion({ actionName: 'getMfgordernameAsync', name: 'mfgordername', value, callback, triggerLength: 2 });
        }

        // 查询发动机号
        async function getEngineNoAsync(value, callback) {
          fetchSuggestion({ actionName: 'getEngineNoAsync', name: 'engineno', value, callback, triggerLength: 2 });
        }

        // 查询数据
        async function getData() {
          dataObj.loading = true;
          dataObj.loadingText = '数据加载中...';
          const { data: { data, meta, total } } = await axios({
            url: '../handler/report/ZSMaterialLackInfoReport.ashx?actions=getData',
            method: 'post',
            data: {
              ...dataObj.queryInfo,
              currentPage: dataObj.currentPage,
              pageSize: dataObj.pageSize,
              type: 'getData'
            }
          })
          dataObj.loading = false;
          if (meta.status === 500) {
            return ElMessage.error(meta.msg);
          }
          dataObj.dataList = data;
          dataObj.total = total;
        };

        // 查看进度弹窗
        async function getContainer(row) {
          const { productname, factorycode } = row;
          if (factorycode === '507') {
            return ElMessage.error('外购件无法查看进度!');
          }
          dataObj.containerDetail.dialogVisiable = true;
          dataObj.containerDetail.title = `${productname}批次进度`;
          dataObj.loading = true;
          dataObj.loadingText = '数据加载中...';
          const { data: { data, meta, total } } = await axios({
            url: '../handler/report/ZSMaterialLackInfoReport.ashx?actions=getContainer',
            method: 'post',
            data: { type: 'getContainer', productname, factorycode }
          })
          dataObj.loading = false;
          if (meta.status === 500) {
            return ElMessage.error(meta.msg);
          }
          dataObj.containerDetail.dataList = data;
          dataObj.containerDetail.total = total;
        }

        // 导出excel
        function getExportExcel() {
          const config = {
            url: '../handler/report/ZSMaterialLackInfoReport.ashx?actions=exportExcel',
            data: { ...dataObj.queryInfo }
          }
          exportExcel(config, dataObj, ElMessage);
        };

        function handleCurrentChange(newPage) {
          dataObj.currentPage = newPage;
          getData();
        };

        function handleSizeChange(newSize) {
          dataObj.pageSize = newSize;
          getData();
        };

        onMounted(() => { })

        watch(() => dataObj.queryInfo, () => {
          dataObj.currentPage = 1;
        }, { deep: true })

        return {
          dataObj,
          getData,
          getExportExcel,
          handleCurrentChange,
          handleSizeChange,
          getProductnameAsync,
          getMfgordernameAsync,
          getEngineNoAsync,
          getContainer,
          splitDate
        }
      }
    };

    const app = createApp(App);
    app.use(ElementPlus, {
      locale: ElementPlusLocaleZhCn,
      size: 'large'
    });
    // 注册所有icon
    for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
      app.component(key, component)
    }
    app.component('vue3-report-header', Vue3ReportHeader);
    app.mount('#app');
  </script>
</body>

</html>